#include <gtk/gtk.h>
#include "common.h"

void enter_button_callback(GtkWidget *widget, gpointer data);
void frame_callback(GtkWindow *window, GdkEvent *event, gpointer data);

static void configure_event_test(GtkWidget *window);
static void enter_signal_test(GtkWidget *window);


int main( int argc, char *argv[]){
    GtkWidget *window;

    gtk_init(&argc, &argv);

    /* window */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_set_size_request (window, 300, 250);         /*设置窗口大小*/
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);    /*设置窗口不能拉伸*/
    gtk_window_set_title(GTK_WINDOW(window), TITLE);
    gtk_container_set_border_width(GTK_CONTAINER(window), 15);  /*设置容器边界大小*/

    configure_event_test(window);
    enter_signal_test(window);


    g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(frame_callback), NULL);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

static void configure_event_test(GtkWidget *window)
{
    gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);
    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), G_OBJECT(window));

}

void enter_button_callback(GtkWidget *widget, gpointer data)
{
    GdkColor color;
    color.red = 27000;
    color.green = 30325;
    color.blue = 34181;

    gtk_widget_modify_bg(widget, GTK_STATE_PRELIGHT, &color);
    color.blue = 0;
    gtk_widget_modify_bg(widget, GTK_STATE_ACTIVE, &color);
}

static void enter_signal_test(GtkWidget *window)
{
    GtkWidget *fixed;
    GtkWidget *button;

    fixed = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed);

    button = gtk_button_new_with_label("Button");
    gtk_widget_set_size_request(button, 80, 35);

    gtk_fixed_put(GTK_FIXED(fixed), button, 50, 50);

    g_signal_connect(G_OBJECT(button), "enter", G_CALLBACK(enter_button_callback), NULL);

}

void frame_callback(GtkWindow *window, GdkEvent *event, gpointer data)
{
    int x, y;
    char buf[10];
    x = event->configure.x;
    y = event->configure.y;
    sprintf(buf, "%d, %d", x, y);
    gtk_window_set_title(window, buf);
}
